package org.xq.shop.maxaishop.entity;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * (XqAdmin)实体类
 *
 * @author makejava
 * @since 2021-06-11 18:17:22
 */
@ApiModel("系统用户对象")
@ToString
@Data
public class XqAdmin implements Serializable, UserDetails {
    private static final long serialVersionUID = -80714236837710085L;
    /**
     * 主键id
     */
    private Integer aid;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 昵称
     */
    private String anname;
    /**
     * 性别
     */
    private String asex;
    /**
     * 头像
     */
    private String aimage;
    /**
     * 电话
     */
    private String atel;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 部门
     */
    private String adepartment;
    /**
     * 创建时间
     */
    private String atime;


    private Integer roleId;


    /**
     * 状态
     */
    private Integer status;

    private List<XqRole> roles;

    /**
     * 获取权限方法
     * @return
     */
    @JSONField(serialize = false)
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(roles == null || roles.size()<=0){
            return null;
        }
        List<GrantedAuthority> authorities = new ArrayList<>();
        for(XqRole role:roles){
            authorities.add(role);
        }
        return authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }
    @JSONField(serialize = false)
    //true：账号未过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JSONField(serialize = false)
    //true：账号未锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    @JSONField(serialize = false)
    //true：凭证未过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    @JSONField(serialize = false)
    //true：账号可用
    @Override
    public boolean isEnabled() {
        return true;
    }
}